<?php

namespace apiend\modules\test\controllers;

use Yii;
use yii\web\Controller;
use apiend\models\User;

/**
 * Default controller for the `test` module
 */
class DefaultController extends Controller {

    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionIndex() {

        return \common\models\user\UserCoupon::findDiscountValue(1005);

        return \common\helpers\IpHelper::long2ip(659725386, false);

        $account = '1';
        $query = User::find()->where([
            'status' => User::STATUS_ACTIVE
        ])->andWhere([
            'or',
            ['username' => $account],
            ['mobile' => $account],
            ['email' => $account],
        ]);
        $user = $query->one();

        return [
            'sql' => \common\helpers\Debug::sql($query),
            'data' => $user
        ];


        /* @var $queue \yii\queue\Queue */
        $cache = Yii::$app->cache;
        $cache->set('test', 'test');

        return $cache->get('test');
        return ['test'];
        /* @var $queue \yii\queue\Queue */
        $queue = Yii::$app->queue;

//        return $id = $queue->push(new \common\jobs\TestJob([
//            'content' => 'test',
//            'data' => ['testdata'],
//        ]));
//        $tokens = [
//            '18171adc03323865650'
//        ];
//        return $id = $queue->push(new \common\jobs\JPushJob([
//            'title' => 'TEST尊敬的用户，有人在动态内容中@到您，点击查看',
//            'redirect' => 'lnts://web?link=https://daas.lnts.cn/m/user/birthday/1',
//            'tokens' => $tokens,
//        ]));


        $usernames = [
            '呆萌的Insomnia小姐',
            '最神奇的视频',
            '贴吧娘',
            'R0xy',
            '豆瓣说',
        ];
        $dynamic_id = 5;

        return $queue->push(new \common\jobs\DynamicAtNoticeJob([
            'usernames' => $usernames,
            'dynamic_id' => $dynamic_id,
        ]));


        return $id = $queue->push(new \common\jobs\TestRetryableJob([
            'content' => 'test'
        ]));
        $id = 28;
        return $queue->isDone($id);
        return $users = \common\models\user\User::find()->each();

        $query = \common\models\user\User::find()->filterWhere([
            'id' => [1, 2]
        ])->joinWith('students s')->select('s.push_token');

        $users = $query->all();

        $data[] = $users;
        $data[] = \common\helpers\Debug::sql($query);

        return $data;
        $array = [];
        $content = '@_呆萌的Insomnia小姐 @最神奇的视频 卧槽 #阴阳师手游#  //@贴吧娘:哈哈哈哈哈哈，是我本人没错了//@R0xy:哈哈哈哈哈哈哈哈哈哈//@豆瓣说:下一顿一定不吃了@呆萌的Insomnia小姐';

        return \common\helpers\StringHelper::matchTopic($content);
        //preg_match_all("/\@([^\s|\/|:|\@]+)/", $content, $array);

        preg_match_all("/\#([^\#]+)\#/", $content, $array);



        $array[] = $content;
        return $array;
    }

}
